<?php

namespace App\Import;

use App\Models\OrderModel;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

class OrderImport implements ToCollection
{
  public function collection(Collection $collection): void
  {
    $data = $collection->groupBy(0)->toArray();
    foreach ($data as $key => $value) {
      if ($key && str_contains($key, '20')) {
        if (isset($value[0][2]) && $value[0][2]) {
          $order = OrderModel::where('order_no', $key)->first();
          if ($order->finish_status) {
            continue;
          }
          if ($order->pay_status) {
			//$order->express_company = $value[0][1];
            $order->express_no = $value[0][2];
            $order->express_status = 1;
            $order->save();
          }
        }
      }
    }
  }
}
